/***************************************************************************** 

  ByteReader
  ----------

  Class making your life easier if you have to read single bits from a buffer

  by yoda

  WWW:      y0da.cjb.net
  E-mail:   LordPE@gmx.net

  You are allowed to use this class in your own projects if you keep this
  trademark.

*****************************************************************************/

#pragma once

#include <windows.h>

//
// ByteReader class
//
class ByteReader
{
public:
	ByteReader(void);
	ByteReader( void* pBuff, DWORD dwSize );
	~ByteReader(void);

	void    InitVars();
	BOOL    Assign( void *pBuff, DWORD dwSize );
	DWORD   GetUnusedBitCount();
	DWORD   GetTotalBitCount();
	DWORD   GetReadByteCount();
	BYTE    ReadBit();
	BYTE    ReadByte();
	WORD    ReadWord();
	DWORD   ReadDword();
	DWORD   ReadBits( DWORD dwBitCount );

protected:
	void*          pBuffer;
	DWORD          cbBuffer, dwBitsLeft, dwBitsTotal, dwIndex;
	BYTE           byCur;
	BYTE           byBits2Do;
};

typedef ByteReader *PByteReader;